
def isPrime(a):
    if a == 1:
        return False
    test = True
    b = a - 1
    while b > 1:
        if not a % b:
            test = False
            break
        b -= 1
    return test
n = input()
m = []
for i in range(len(n)):
    for  b in range(i + 1, len(n) + 1):
        a  = int(n[i:b])
        if isPrime(a):
            m += [a]
print(max(m) if m else 0)
